/*
    SUSAN® - Sole of Unix Save ANything

   
      Copyright (C) 2011-2016 Skyatlas Co. LTD

   

   
*/

#include "lib/susan_resource.h"

const char* GetResourceName(void* resource)
{
  return ((SusanResource*)resource)->resource_name_;
}

SusanResource::SusanResource()
    : next_(nullptr)
    , resource_name_(nullptr)
    , description_(nullptr)
    , rcode_(0)
    , refcnt_(0)
    , item_present_{0}
    , inherit_content_{0}
{
  return;
}

SusanResource::SusanResource(const SusanResource& other)
{
  /* do not copy next_ because that is part of the resource chain */
  next_ = nullptr;
  resource_name_ =
      other.resource_name_ ? strdup(other.resource_name_) : nullptr;
  description_ = other.description_ ? strdup(other.description_) : nullptr;
  rcode_ = other.rcode_;
  refcnt_ = other.refcnt_;
  ::memcpy(item_present_, other.item_present_, MAX_RES_ITEMS);
  ::memcpy(inherit_content_, other.inherit_content_, MAX_RES_ITEMS);
}

bool SusanResource::Validate() { return true; }

SusanResource& SusanResource::operator=(const SusanResource& rhs)
{
  next_ = rhs.next_;
  resource_name_ = rhs.resource_name_;
  description_ = rhs.description_;
  rcode_ = rhs.rcode_;
  refcnt_ = rhs.refcnt_;
  ::memcpy(item_present_, rhs.item_present_, MAX_RES_ITEMS);
  ::memcpy(inherit_content_, rhs.inherit_content_, MAX_RES_ITEMS);
  return *this;
}
